﻿using DevelopTool.Common;
using DevelopTool.Forms.BaseForms;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace DevelopTool.Forms.CommonForms
{
    /// <summary>
    /// 选择热键窗口
    /// </summary>
    public partial class ChoiceHotKeyForm : BaseUIForm
    {
        private string titleText;

        /// <summary>
        /// 窗口标题文本
        /// </summary>
        public string TitleText
        {
            get
            {
                return this.titleText;
            }
            set
            {
                this.titleText = value;
            }
        }



        private string keyStr = "无";

        /// <summary>
        /// 热键
        /// </summary>
        public string KeyStr
        {
            get
            {
                return this.keyStr;
            }
            set
            {
                this.keyStr = value;
            }
        }

        private HashSet<string> keyStrList = new HashSet<string>();

        private HashSet<int> keyValues = new HashSet<int>();


        public ChoiceHotKeyForm()
        {
            InitializeComponent();
        }

        private void SetHotKeyForm_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(titleText)) this.Text = titleText;

            this.pnlKey.Text = this.keyStr;

            ThemHelper.SetSystemThem(this);
        }


        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.keyValues.Count > 0)
            {
                this.keyStr = HotKeyHelper.GetSunnyUIHotKeyStr(this.keyValues.ToList());
                this.DialogResult = DialogResult.OK;
            }
            else {
                this.DialogResult = DialogResult.Ignore;
            }            
        }


        private void pnlKey_KeyDown(object sender, KeyEventArgs e)
        {
            string keyCodeStr = e.KeyCode.ToString();

            if (keyCodeStr == "Return") return;

            if (!this.keyStrList.Contains(keyCodeStr))
            {
                if (e.KeyValue == 16)
                {
                    keyCodeStr = "Shift";
                }
                else if (e.KeyValue == 17)
                {
                    keyCodeStr = "Ctrl";
                }
                else if (e.KeyValue == 18)
                {
                    keyCodeStr = "Alt";
                }

                this.keyStrList.Add(keyCodeStr);
                this.keyValues.Add(e.KeyValue);
                this.pnlKey.Text = string.Join("+", this.keyStrList);

            }
        }


    }
}
